package jjn.acwing.weekly;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/19 19:31
 */
public class Acwing5139 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int count = scanner.nextInt();
        Map<String, Integer> map = new HashMap<>();
        map.put("bessie", 1);
        int res = 0;
        for (int i = 0; i < count; i++) {
            String a = scanner.next().toLowerCase();
            String b = scanner.next().toLowerCase();
            int h = map.getOrDefault(b, 0) + 1;
            map.put(a, h);
            res = Math.max(res, map.get(a));
        }
        System.out.println(res);
    }
    
}
